<?php
require_once 'ReservationView.php';
	class KeyDepositManager{
	
		public function validate($snum,$term,$ornum,$amount,$dateReceived,$dateReturned,$remarks){
		
			if(is_numeric($snum)&&($term!=""||$term!=null)&&($ornum!=""||$ornum!=null)&&($amount!=""||$amount!=null)&&($dateReceived!=""||$dateReceived!=null)){
					return true;
				}else{
					return false;
			}
		}
		
		public function insertKey($snum,$term,$ornum,$amount,$dateReceived,$dateReturned,$remarks){	
			$conn=oci_connect("naiad","1234","localhost/XE");
			if(!$conn){
				$err[] = "Connection error!". var_dump(oci_error());
				echo '<script> alert("'.$err.'") </script>';
				die();
				oci_close($conn);
			}
			else{
				$stkey = oci_parse($conn,"insert into keydeposit(studentno,term,ornum,amount,datereceived,datereturned,remarks) values(:studentno,:term,:ornum,:amount,:datereceived,:datereturned,:remarks)");
				oci_bind_by_name($stkey, ":studentno", $snum);
				oci_bind_by_name($stkey, ":term", $term);
				oci_bind_by_name($stkey, ":ornum", $ornum);
				oci_bind_by_name($stkey, ":amount", $amount);
				oci_bind_by_name($stkey, ":datereceived", $dateReceived);
				oci_bind_by_name($stkey, ":datereturned", $dateReturned);
				oci_bind_by_name($stkey, ":remarks", $remarks);


				$exec1 = oci_execute($stkey);
				if($exec1==true){
					return 1;
				}
				oci_commit($conn);
				//oci_free_statement($stid);
				oci_close($conn);
			}	
		}		
	}//class
?>
